package com.jinwei.servicefeign;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.client.RestTemplate;


//申明这是一个Spring Boot项目
@SpringBootApplication
// 扫描注解，自动装配
@ComponentScan(basePackages = {"com.jinwei.servicefeign.controller", "com.jinwei.servicefeign.api"})
//设置服务调用端
@EnableEurekaClient
//启用 熔断
@EnableHystrix
//启用接口伪装
@EnableFeignClients(basePackages = "com.jinwei.servicefeign.api")
public class ServiceFeignApplication {

    public static void main(String[] args) {
        System.out.println("Fegin客户端启启动了");
        SpringApplication.run(ServiceFeignApplication.class, args);
    }

    /**
     * 向Spring容器中定义RestTemplate对象 ,这样一定要加上，不然会出错
     *
     * @return
     */
    @Bean
    @LoadBalanced  //Ribbon 负载均衡
    public RestTemplate restTemplate() {
        System.out.println("。。负载均衡。。。");
        return new RestTemplate();
    }


}
